/**
 * Copyright &copy; 2012-2016 <a href="https://www.kaaction.com">KAA</a> All rights reserved All rights reserved.
 */
package com.kaaction.modules.mer.service;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Lists;
import com.kaaction.common.persistence.Page;
import com.kaaction.common.service.CrudService;
import com.kaaction.modules.mer.entity.OperationSubject;
import com.kaaction.modules.mer.dao.OperationSubjectDao;
import com.kaaction.modules.mer.dao.OperationSubjectDetailDao;

/**
 * 运营专题Service
 * @author huanghaiming
 * @version 2017-07-04
 */
@Service
@Transactional(readOnly = true)
public class OperationSubjectService extends CrudService<OperationSubjectDao, OperationSubject> {
	
	@Autowired
	OperationSubjectDetailDao operationSubjectDetailDao;
	
	@Autowired
	SpuService spuService;

	public OperationSubject get(String id) {
		return super.get(id);
	}
	
	public List<OperationSubject> findList(OperationSubject operationSubject) {
		return super.findList(operationSubject);
	}
	
	public Page<OperationSubject> findPage(Page<OperationSubject> page, OperationSubject operationSubject) {
		return super.findPage(page, operationSubject);
	}
	
	@Transactional(readOnly = false)
	public void save(OperationSubject operationSubject) {
		super.save(operationSubject);
	}
	
	@Transactional(readOnly = false)
	public void delete(OperationSubject operationSubject) {
		super.delete(operationSubject);
	}

	@Transactional(readOnly = false)
	public void updateIsShow(OperationSubject operationSubject) {
		super.dao.updateIsShow(operationSubject);
	}

	public List<Map<String,Object>> selOperSubject() {
		return super.dao.selOperSubject();
	}

	public List<Map<String,Object>> selOperSubjectContent(String id) {
			
		List<Map<String,Object>> listMap = Lists.newArrayList();
		
		List<Map<String,Object>>  listCont = operationSubjectDetailDao.selOperSubDtl(id);
		
		if(listCont.size()>0){
			
			for(Map<String,Object> mapCont:listCont){
				
				String opercontentId = (String) mapCont.get("opercontentId");
				if(StringUtils.isNotBlank(opercontentId)){
					mapCont.put("listSpu", spuService.selSup(opercontentId));
					listMap.add(mapCont);
				}
			}
		}
		return listMap;
	}
	
}